package com.taofuxn.yycreazy.mvp.presenter;

import com.taofuxn.yycreazy.mvp.BasePresenter;
import com.taofuxn.yycreazy.mvp.model.NewsertJokBean;
import com.taofuxn.yycreazy.mvp.view.ISpecialView;
import com.taofuxn.yycreazy.retrofit.ApiStore;
import com.taofuxn.yycreazy.retrofit.Key;
import com.taofuxn.yycreazy.rxjava.ApiCallback;
import com.taofuxn.yycreazy.rxjava.SubscriberCallback;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by wanghuafu on 16/9/16.
 */
public class SpecialPresenter extends BasePresenter {

    private ISpecialView iSpecialView;

    public SpecialPresenter(ISpecialView iSpecialView) {
        onAttachView(iSpecialView);
        this.iSpecialView = iSpecialView;
    }


    public void loadData(final boolean isReflash,int page) {

        HashMap<String, String> params = new HashMap<>();
        params.put("page", page+"");
        params.put("pagesize", "10");
        params.put("key", Key.jokey);

        addSubscription(mRetrofit.create(ApiStore.class).getDataByMostNew(params), new SubscriberCallback(new ApiCallback() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onFailed(int code, String msg) {

            }

            @Override
            public void onSuccess(Object o) {
                NewsertJokBean response = (NewsertJokBean) o;
                iSpecialView.dimissLoading();
                if (isReflash)
                    iSpecialView.reqSuccess((ArrayList<NewsertJokBean.NewsertJokResult.NewsertJok>) response.result.data);
                else
                    iSpecialView.loadmoreSuccess(response.result.data);
            }
        }));
    }

}
